package logic

import (
	"context"
	"go-zero-all-demos/apps/user/models"

	"go-zero-all-demos/apps/user/pb/user"
	"go-zero-all-demos/apps/user/rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserLogic {
	return &UpdateUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// UpdateUser 用户更新
func (l *UpdateUserLogic) UpdateUser(in *user.UserInfo) (*user.Empty, error) {
	err := l.svcCtx.UserModel.Update(l.ctx, nil, &models.User{Id: in.Id, Name: in.Name, Password: in.Password})
	if err != nil {
		return nil, err
	}
	return &user.Empty{}, nil
}
